#include "DerivationTree.h"
#include "CallInstruction.h"
#include <cmath>
using namespace std;

UnaryMinusNode::UnaryMinusNode() : NodeTree_CRTP<UnaryMinusNode>() { }

UnaryMinusNode::UnaryMinusNode(const AutoPointer<NodeTree>& _argument) : NodeTree_CRTP<UnaryMinusNode>(), argument(_argument) { }

UnaryMinusNode::UnaryMinusNode(const UnaryMinusNode& copy) : NodeTree_CRTP<UnaryMinusNode>(copy), argument(copy.argument) { }

bool UnaryMinusNode::execute(Pointer<LeonardVirtualMachine> LVM) {
	argument->execute(LVM);
	AutoPointer<TreeExpression::Expression> first = LVM->top();
	LVM->pop();
	TreeExpression::CallInstruction* minusCall = new TreeExpression::CallInstruction("operator-");
	minusCall->setSon(first);
	AutoPointer<TreeExpression::Expression> ris(minusCall);
	LVM->push(ris);
	return true;
}
